/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.foxline.converter;

import br.com.foxline.model.Enterprise;
import br.com.foxline.service.EnterpriseService;
import javax.ejb.EJB;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

/**
 *
 * @author roniere
 */
@FacesConverter(value = "enterpriseconverter")
public class EnterpriseConverter implements Converter{
    
    @EJB
    EnterpriseService enterpriseService;
    
     @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
        Enterprise enterprise = new Enterprise();
        if(value != null){
           enterprise =  enterpriseService.find(Long.valueOf(value));
        }
        return enterprise ;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        Enterprise enterprise = (Enterprise) value;
        return "" + enterprise.getId();
    }
    
}
